<template>
  <view class="menu-group">
    <view class="group-title">{{ title }}</view>
    <view 
      class="menu-item"
      v-for="item in menuItems"
      :key="item.key"
      @click="handleItemClick(item)"
    >
      <view class="menu-icon" :style="{ backgroundColor: item.color }">
        <text class="iconfont" :class="item.icon"></text>
      </view>
      <view class="menu-content">
        <view class="menu-title">{{ item.title }}</view>
        <view class="menu-desc" v-if="item.desc">{{ item.desc }}</view>
      </view>
      <view class="menu-switch" v-if="item.type === 'switch'">
        <switch 
          :checked="getSettingValue(item.key)"
          @change="handleSwitchChange(item.key, $event)"
          color="#1890ff"
        />
      </view>
      <view class="menu-extra" v-else-if="item.extra">
        <text class="extra-text">{{ item.extra }}</text>
      </view>
      <view class="menu-badge" v-else-if="item.badge">
        {{ item.badge }}
      </view>
      <view class="menu-arrow" v-if="item.type !== 'switch'">
        <text class="iconfont icon-arrow-right"></text>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  name: 'MenuGroup',
  props: {
    title: {
      type: String,
      required: true
    },
    menuItems: {
      type: Array,
      default: () => []
    },
    getSettingValue: {
      type: Function,
      default: () => false
    }
  },
  emits: ['item-click', 'switch-change'],
  methods: {
    handleItemClick(item) {
      this.$emit('item-click', item)
    },
    handleSwitchChange(key, event) {
      this.$emit('switch-change', key, event)
    }
  }
}
</script>

<style lang="scss" scoped>
.menu-group {
  background: linear-gradient(135deg, #ffffff 0%, #fafbfc 100%);
  border-radius: 24rpx;
  margin-bottom: 20rpx;
  overflow: hidden;
  box-shadow: 
    0 8rpx 32rpx rgba(0, 0, 0, 0.08),
    0 1rpx 0 rgba(255, 255, 255, 0.8),
    inset 0 1rpx 0 rgba(255, 255, 255, 0.9);
  border: 1rpx solid rgba(0, 0, 0, 0.05);
  transition: all 0.3s ease;
  
  &:hover {
    transform: translateY(-2rpx);
    box-shadow: 
      0 12rpx 48rpx rgba(0, 0, 0, 0.12),
      0 1rpx 0 rgba(255, 255, 255, 0.8),
      inset 0 1rpx 0 rgba(255, 255, 255, 0.9);
  }
}

.group-title {
  font-size: 28rpx;
  font-weight: 500;
  color: #262626;
  padding: 32rpx 32rpx 16rpx;
}

.menu-item {
  display: flex;
  align-items: center;
  padding: 28rpx 32rpx;
  border-bottom: 1rpx solid rgba(0, 0, 0, 0.05);
  transition: all 0.3s ease;
  position: relative;
  
  &:last-child {
    border-bottom: none;
  }
  
  &::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 0;
    background: linear-gradient(90deg, rgba(24, 144, 255, 0.05) 0%, transparent 100%);
    transition: width 0.3s ease;
  }
  
  &:active {
    background: linear-gradient(135deg, rgba(24, 144, 255, 0.02) 0%, rgba(64, 169, 255, 0.03) 100%);
    transform: scale(0.98);
    
    &::before {
      width: 8rpx;
    }
  }
  
  &:hover {
    background: rgba(24, 144, 255, 0.02);
    
    &::before {
      width: 4rpx;
    }
  }
}

.menu-icon {
  width: 68rpx;
  height: 68rpx;
  border-radius: 18rpx;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 28rpx;
  box-shadow: 
    0 4rpx 16rpx rgba(0, 0, 0, 0.15),
    inset 0 1rpx 0 rgba(255, 255, 255, 0.2);
  transition: all 0.3s ease;
  position: relative;
  
  &::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    border-radius: 18rpx;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.2) 0%, transparent 50%, rgba(0, 0, 0, 0.1) 100%);
  }
  
  .iconfont {
    font-size: 30rpx;
    color: white;
    z-index: 1;
    position: relative;
    text-shadow: 0 1rpx 2rpx rgba(0, 0, 0, 0.3);
  }
  
  .menu-item:active & {
    transform: scale(0.95);
    box-shadow: 
      0 2rpx 8rpx rgba(0, 0, 0, 0.2),
      inset 0 1rpx 0 rgba(255, 255, 255, 0.2);
  }
}

.menu-content {
  flex: 1;
}

.menu-title {
  font-size: 28rpx;
  color: #262626;
  margin-bottom: 4rpx;
}

.menu-desc {
  font-size: 22rpx;
  color: #8c8c8c;
  line-height: 1.4;
}

.menu-extra {
  margin-right: 16rpx;
  
  .extra-text {
    font-size: 24rpx;
    color: #8c8c8c;
  }
}

.menu-switch {
  margin-right: 16rpx;
}

.menu-badge {
  background: #f5222d;
  color: white;
  font-size: 20rpx;
  padding: 4rpx 12rpx;
  border-radius: 16rpx;
  margin-right: 16rpx;
}

.menu-arrow {
  color: #bfbfbf;
  
  .iconfont {
    font-size: 24rpx;
  }
}
</style>